/*
 * @dependancies:mootools<http://mootools.net>
 * 
 * @author: xalinx@gmail.com
 * @date: 2006-12-25 
 */
//---- constructor ----
function FloatWindow(panel, option){
	this._initOption(option);	
	this._panel=$(panel);
}

FloatWindow.prototype={
//---- private properties ----	
	/**
	 * Show panel.
	 */
	_panel:null,
	/**
	 * Show task.
	 */
	_timeout_task:null,
	/**
	 * Event target.
	 */
	_from:null,
	/**
	 * Tag indicate show status.
	 */
	_show_tag:false,
//---- public method ----	
	show:function(event) {
		if(this._show_tag)return;
		this._from=event.target||event.srcElement;
		var self=this;
		this._timeout_task=setTimeout(function(){self._show()}, this._timeout);
	},
	hide:function(event) {
		if(!this._show_tag)return;
		if(event){
			var _to=event.relatedTarget||event.toElement;
			while(_to){
				if(_to==this._panel||_to==this._from)return;
				_to= _to.parentNode;
			}
		}
		clearTimeout(this._timeout_task);
		this._panel.style.display='none';
		this._show_tag=false;
		this._onComplete.apply(this);
	},
	reset:function(option){
		if(!option)return;
		if(option.x)this._x=option.x;
		if(option.y)this._y=option.y;
		if(option.layout)this._layout=option.layout;
		if(option.timeout)this._timeout=option.timeout;
		if(option.onStart)this._onStart=option.onStart;
		if(option.onComplete)this._onComplete=option.onComplete;		
	},
//---- private method ----
	_initOption:function(option){
		var option=option||{};
		this._x=option.x||0;
		this._y=option.y||0;
		this._layout=option.layout||"right";
		this._timeout=option.timeout?option.timeout:0;
		this._onStart=option.onStart||Class.empty;
		this._onComplete=option.onComplete||Class.empty;	
	},
	_show:function() {
		this._panel.style.display='block';
		var tw=this._from.offsetWidth;
		var th=this._from.offsetHeight;
		var pw=this._panel.offsetWidth;
		var ph=this._panel.offsetHeight;
		var sw=sh=0;
		if("right"==this._layout)sw+=tw;
		else if("left"==this._layout)sw-=pw;
		else if("bottom"==this._layout)sh+=th;
		else if("top"==this._layout)sh-=ph;
		var pos=this._getPosXY(this._from);
		this._panel.style.left=pos[0]+sw+this._x+'px';
		this._panel.style.top=pos[1]+sh+this._y+'px';
		this._show_tag=true;
		this._onStart.apply(this);
	},
	_getPosXY:function(a) {
		var p=[0,0];
		var tn;
		while(a) {
			tn=a.tagName.toUpperCase();
			p[0]+=a.offsetLeft-(tn=="DIV"&&a.scrollLeft?a.scrollLeft:0);
			p[1]+=a.offsetTop-(tn=="DIV"&&a.scrollTop?a.scrollTop:0);
			if (tn=="BODY") break;
			a=a.offsetParent;
		}
		return p;
	}/*
	_getPosXY:function(a) {
		var p=[0,0];
		var tn;
		while(a) {
			tn=a.tagName.toUpperCase();
			if (this._getStyle(a, 'position') == 'relative') {
				a=a.offsetParent;
				continue;			
			}
			p[0]+=a.offsetLeft-(tn=="DIV"&&a.scrollLeft?a.scrollLeft:0);
			p[1]+=a.offsetTop-(tn=="DIV"&&a.scrollTop?a.scrollTop:0);
			if (tn=="BODY" || tn == "HTML") break;
			a=a.offsetParent;
		}
		return p;
	},
	
	_getStyle: function(element, prop) {
	  if (element.style[prop]) {
	    // inline style property
	    return element.style[prop];
	  } else if (element.currentStyle) {
	    // external stylesheet for Explorer
	    return element.currentStyle[prop];
	  } else if (document.defaultView && document.defaultView.getComputedStyle) {
	    // external stylesheet for Mozilla and Safari 1.3+
	    prop = prop.replace(/([A-Z])/g,"-$1");
	    prop = prop.toLowerCase();
	    return document.defaultView.getComputedStyle(element,"").getPropertyValue(prop);
	  } else {
	    // Safari 1.2
	    return null;
	  }
	} */	
}